﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShiXuLong.Service;
using ShiXuLong.Model;

namespace ShiXuLong.Web.Controllers
{
    [Authorize]
    public class UserController : Controller
    {
        UserService user = new UserService();
        // GET: User
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult GetUser()
        {
            var list = user.GetShow();
            return Json(new { code = 0, msg = "", count = 10, data = list }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 显示编辑页面
        /// </summary>
        /// <returns></returns>
        public ActionResult XianShi(int id)
        {
            var users = user.Edit(id);
            return View(users);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <returns></returns>
        ///
        //public ActionResult Edit()
        //{

        //}
        [HttpPost]
        public ActionResult Edit(User users)
        {
            var n = user.EditInfo(users);
            if (n > 0)
            {
                return Json(new { success = true, msg = "修改成功" });
            }
            else
            {
                return Json(new { success = true, msg = "修改失败" });
            }
        }
        public ActionResult DizhiIndex()
        {
            return View();
        }
        public ActionResult GetDizhi()
        {
            var list = user.GetDizhi();
            return Json(new { code = 0, msg = "", count = 10, data = list }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 添加用户地址
        /// </summary>
        /// <returns></returns>
        public ActionResult AddUser(int id)
        {
            var dizhi = user.Show(id);
            return View(dizhi);
        }    
        /// <summary>
        /// 修改
        /// </summary>
        /// <returns></returns>
        ///
        //public ActionResult Edit()
        //{
        //}
        [HttpPost]
        public ActionResult Editdizhi(Address dizhi)
        {
            var n = user.EditDiZhi(dizhi);
            if (n > 0)
            {
                return Json(new { success = true, msg = "修改成功" });
            }
            else
            {
                return Json(new { success = true, msg = "修改失败" });
            }
        }
    }
}